﻿using CKS.Core.Framework;
using CKS.PLC.Action.Subscription.OP080;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ZR.Model.Models.ProductionControl;

namespace CKS.PLC.Action.Subscription.OP80
{
    /// <summary>
    /// 动作编号102
    /// 右钎焊料架-存满工装-保存工装数据
    /// </summary>
    public class DB3011_Work102Action : OP80ActionBase
    {
        public DB3011_Work102Action(DecodeValue _value) : base(_value)
        {
        }
        public override void Execute()
        {
            var replayDB = 3010;
            var replayAction = 2;
            var result = Value.Value.ToInt();
            var locationId = 2;//位置编号 1左 2右
            if (result == 1)
            {
                CatchAction(() => { SaveFixtureInfos(locationId); }, "OP80请求保存-右-钎焊料架");

               
                // db.Insertable(dc).ExecuteCommand();

                //保存数据
                //读取子篮二维码和检测结果
                //string barcode = Value.GetLinkData(1).ToString();
                //int flag = Value.GetLinkData(2).ToInt();

                //logger.LogInformation($"保存数据 子篮码{barcode} 检测结果{flag}");
                //查找保存完成点位
                EventBus.AddLog("OP80请求保存-右-钎焊料架");
                var replayPos = Value.GetPosition(replayDB, replayAction);
                AckWriteInt16(replayPos, 1);
            }
            else
            {
                var replayPos = Value.GetPosition(replayDB, replayAction);
                AckWriteInt16(replayPos, 0);
                EventBus.AddLog($"OP80请求保存-右-钎焊料架-信号重置");
            }
        }

        
    }
}
